/**
 * 
 */
package org.mspring.mlog.web.query.bbs;

import java.util.Date;
import java.util.Map;

import org.mspring.platform.dao.support.query.AbstractQueryCriterion;
import org.mspring.platform.dao.support.query.QueryBuilder;

/**
 * @author Gao Youbo
 * @since 2013-01-13
 */
public class TopicQueryCriterion extends AbstractQueryCriterion {

    private String queryString;
    private String countString;
    private String whereString;

    /**
     * 
     */
    @SuppressWarnings("rawtypes")
    public TopicQueryCriterion(Map queryParams) {
        // TODO Auto-generated constructor stub
        QueryBuilder builder = new QueryBuilder(queryParams);
        builder.startBuild();
        builder.buildEqual("topic.forum.id", "forum.id", Long.class);
        builder.buildEqual("topic.author.id", "author.id", Long.class);
        builder.buildLike("topic.author.name", "author.name");
        builder.buildLike("topic.author.alias", "author.alias");
        builder.buildLike("topic.title", "title");

        // builder.buildGE("topic.createTime", "createTimeBeg", Date.class);
        // builder.buildLE("topic.createTime", "createTimeEnd", Date.class);

        builder.buildBetween("topic.createTime", "createTimeBeg", "createTimeEnd", Date.class);

        whereString = builder.endBuild();

        namedQueryParams = builder.getNamedQueryParams();
        queryParamsString = builder.getQueryParamsAsString();

        queryString = "select topic from Topic topic ";
        countString = "select count(*) from Topic topic ";
    }

    @Override
    public String getQueryString() {
        // TODO Auto-generated method stub
        return queryString + whereString;
    }

    @Override
    public String getCountString() {
        // TODO Auto-generated method stub
        return countString + whereString;
    }

}
